/*
 * CoefficientValueSettingFrame.java
 *
 * Created on Nov 25, 2011, 7:56:29 AM
 */
package gui;

/**
 *
 * @author suzann
 */
/*
 * Import Java Classes
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferStrategy;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

import db.DatabaseManager;
import db.entity.Coefficient;
import db.entity.CoefficientPK;

import util.Activity;
import util.Authentication;
import util.PropertiesLoader;
import util.Validator;
public class CoefficientValueSettingFrame extends javax.swing.JFrame {
    
    private static final long serialVersionUID = 1L;
    /** Creates new form CoefficientValueSettingFrame */
    public CoefficientValueSettingFrame() {
        initComponents();
        toggleTextAndButtons(false);
        setDefaultValue();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jlbPolisher = new javax.swing.JLabel();
        jcbPolisher = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jlbLfactor = new javax.swing.JLabel();
        jlbL1 = new javax.swing.JLabel();
        jlbL2 = new javax.swing.JLabel();
        jlbL3 = new javax.swing.JLabel();
        jlbL4 = new javax.swing.JLabel();
        jlbL5 = new javax.swing.JLabel();
        jlbL6 = new javax.swing.JLabel();
        jlbL10 = new javax.swing.JLabel();
        jlbL11 = new javax.swing.JLabel();
        jspnL1KA = new javax.swing.JSpinner();
        jspnL1KB = new javax.swing.JSpinner();
        jspnL1KC = new javax.swing.JSpinner();
        jspnL1KD = new javax.swing.JSpinner();
        jspnL1KE = new javax.swing.JSpinner();
        jspnL1KF = new javax.swing.JSpinner();
        jspnLBandC = new javax.swing.JSpinner();
        jspnLBandE = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jspnTargetTaperL = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jspnUCLTaperL = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        jspnLCLTaperL = new javax.swing.JSpinner();
        jPanel2 = new javax.swing.JPanel();
        jlbRfactor = new javax.swing.JLabel();
        jlbR1 = new javax.swing.JLabel();
        jlbR2 = new javax.swing.JLabel();
        jlbR3 = new javax.swing.JLabel();
        jlbR4 = new javax.swing.JLabel();
        jlbR5 = new javax.swing.JLabel();
        jlbR6 = new javax.swing.JLabel();
        jlbL12 = new javax.swing.JLabel();
        jlbL13 = new javax.swing.JLabel();
        jspnR1KA = new javax.swing.JSpinner();
        jspnRBandC = new javax.swing.JSpinner();
        jspnRBandE = new javax.swing.JSpinner();
        jspnR1KB = new javax.swing.JSpinner();
        jspnR1KC = new javax.swing.JSpinner();
        jspnR1KD = new javax.swing.JSpinner();
        jspnR1KE = new javax.swing.JSpinner();
        jspnR1KF = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jspnTargetTaperR = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        jspnUCLTaperR = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        jspnLCLTaperR = new javax.swing.JSpinner();
        jPanel4 = new javax.swing.JPanel();
        jbtEdit = new javax.swing.JButton();
        jbtSave = new javax.swing.JButton();
        jbtCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setForeground(java.awt.Color.white);
        setMinimumSize(new java.awt.Dimension(621, 500));

        jlbPolisher.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbPolisher.setText("Polisher No:");

        jcbPolisher.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07" }));
        jcbPolisher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPolisherActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlbPolisher)
                .addGap(10, 10, 10)
                .addComponent(jcbPolisher, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(344, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbPolisher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbPolisher))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel3, java.awt.BorderLayout.PAGE_START);

        jPanel5.setMinimumSize(new java.awt.Dimension(621, 2000));
        jPanel5.setPreferredSize(new java.awt.Dimension(621, 2000));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlbLfactor.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbLfactor.setText("Correction Factor L Arm");

        jlbL1.setText("L Arm - KA - Median");

        jlbL2.setText("L Arm - KB - Median");

        jlbL3.setText("L Arm - KC - Median");

        jlbL4.setText("L Arm - KD - Median");

        jlbL5.setText("L Arm - KE - Median");

        jlbL6.setText("L Arm - KF - Median");

        jlbL10.setText("Ratio to Divide C Zone");

        jlbL11.setText("Ratio to Divide E Zone");

        jLabel1.setText("Target Taper");

        jLabel3.setText("UCL Taper");

        jLabel4.setText("LCL Taper");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbLfactor)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlbL6)
                            .addComponent(jlbL5)
                            .addComponent(jlbL4)
                            .addComponent(jlbL3)
                            .addComponent(jlbL2)
                            .addComponent(jlbL1))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jspnL1KA, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnL1KB, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnL1KC, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnL1KD, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnL1KE, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnL1KF, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jlbL10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jspnLBandC, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnLCLTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnUCLTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnTargetTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jlbL11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jspnLBandE, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jlbLfactor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL1)
                    .addComponent(jspnL1KA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL2)
                    .addComponent(jspnL1KB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL3)
                    .addComponent(jspnL1KC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL4)
                    .addComponent(jspnL1KD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL5)
                    .addComponent(jspnL1KE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL6)
                    .addComponent(jspnL1KF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL10)
                    .addComponent(jspnLBandC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL11)
                    .addComponent(jspnLBandE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jspnTargetTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jspnUCLTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jspnLCLTaperL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 351));

        jlbRfactor.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbRfactor.setText("Correction Factor R Arm");

        jlbR1.setText("R Arm - KA - Median");

        jlbR2.setText("R Arm - KB - Median");

        jlbR3.setText("R Arm - KC - Median");

        jlbR4.setText("R Arm - KD - Median");

        jlbR5.setText("R Arm - KE - Median");

        jlbR6.setText("R Arm - KF - Median");

        jlbL12.setText("Ratio to Divide C Zone");

        jlbL13.setText("Ratio to Divide E Zone");

        jLabel2.setText("Target Taper");

        jLabel5.setText("UCL Taper");

        jLabel6.setText("LCL Taper");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbRfactor)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jlbL12)
                        .addGap(18, 18, 18)
                        .addComponent(jspnRBandC, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jlbR6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnR1KF, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jlbR5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnR1KE, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jlbR4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnR1KD, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jlbR3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspnR1KC, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jlbR1)
                                .addComponent(jlbR2))
                            .addGap(32, 32, 32)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jspnR1KB, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jspnR1KA, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlbL13)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jspnLCLTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnUCLTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnTargetTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jspnRBandE, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jlbRfactor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR1)
                    .addComponent(jspnR1KA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR2)
                    .addComponent(jspnR1KB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR3)
                    .addComponent(jspnR1KC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR4)
                    .addComponent(jspnR1KD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR5)
                    .addComponent(jspnR1KE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbR6)
                    .addComponent(jspnR1KF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL12)
                    .addComponent(jspnRBandC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbL13)
                    .addComponent(jspnRBandE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jspnTargetTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jspnUCLTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jspnLCLTaperR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jbtEdit.setText("Edit");
        jbtEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtEditActionPerformed(evt);
            }
        });

        jbtSave.setText("Save");
        jbtSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSaveActionPerformed(evt);
            }
        });

        jbtCancel.setText("Cancel");
        jbtCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtEdit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtCancel)
                .addContainerGap(386, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtCancel)
                    .addComponent(jbtSave)
                    .addComponent(jbtEdit))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(168, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-637)/2, (screenSize.height-638)/2, 637, 638);
    }// </editor-fold>

    /****************************************************************************
     * Action Listeners
     ****************************************************************************/
    private void jbtCancelActionPerformed(java.awt.event.ActionEvent evt) {                                          
        cancelCoefficientValue();
    	toggleTextAndButtons(false);
    }                                         

    private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
        saveCoefficientValue();
    }                                       

    private void jbtEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        editCoefficientValue();
    }                                       

    private void jcbPolisherActionPerformed(java.awt.event.ActionEvent evt) {                                            
        setDefaultValue();
    }                                           
    
    /****************************************************************************
     * Internal Operations
     ****************************************************************************/
    private void setDefaultValue()
    {
    	if(jcbPolisher.getSelectedItem() == null)
    		return ;
    	
    	String polisher = jcbPolisher.getSelectedItem().toString();
    	DatabaseManager db = new DatabaseManager();
    	db.entity.Coefficient coItem = db.listCoefficientByStationArm(polisher, "L");
    	if(coItem == null) 	{
    		jspnL1KA.setValue(0);
        	jspnL1KB.setValue(0);
        	jspnL1KC.setValue(0);
        	jspnL1KD.setValue(0);
        	jspnL1KE.setValue(0);
        	jspnL1KF.setValue(0);
        	jspnLBandC.setValue(0);
            jspnLBandE.setValue(0);
            jspnTargetTaperL.setValue(0);
            jspnUCLTaperL.setValue(0);
            jspnLCLTaperL.setValue(0);   
            
            for(int i=0; i<11; i++)
            	co_L_Value[i] = 0.0;
            
    	} else {
    		jspnL1KA.setValue(coItem.getKa());
        	jspnL1KB.setValue(coItem.getKb());
        	jspnL1KC.setValue(coItem.getKc());
        	jspnL1KD.setValue(coItem.getKd());
        	jspnL1KE.setValue(coItem.getKe());
        	jspnL1KF.setValue(coItem.getKf());
        	jspnLBandC.setValue(coItem.getCPercentage());
            jspnLBandE.setValue(coItem.getEPercentage());
            jspnTargetTaperL.setValue(coItem.getTargetValue());
            jspnUCLTaperL.setValue(coItem.getUcl());
            jspnLCLTaperL.setValue(coItem.getLcl());   
            
            co_L_Value[0] = coItem.getKa();
            co_L_Value[1] = coItem.getKb();
            co_L_Value[2] = coItem.getKc();
            co_L_Value[3] = coItem.getKd();
            co_L_Value[4] = coItem.getKe();
            co_L_Value[5] = coItem.getKf();
            co_L_Value[6] = coItem.getCPercentage();
            co_L_Value[7] = coItem.getEPercentage();
            co_L_Value[8] = coItem.getTargetValue();
            co_L_Value[9] = coItem.getUcl();
            co_L_Value[10] = coItem.getLcl();   
    	}
    	
    	coItem = db.listCoefficientByStationArm(polisher, "R");
    	if(coItem == null) {
            jspnR1KA.setValue(0);
            jspnR1KB.setValue(0);
            jspnR1KC.setValue(0);
            jspnR1KD.setValue(0);
            jspnR1KE.setValue(0);
            jspnR1KF.setValue(0);
            jspnRBandC.setValue(0);
            jspnRBandE.setValue(0);
            jspnTargetTaperR.setValue(0);
            jspnUCLTaperR.setValue(0);
            jspnLCLTaperR.setValue(0);
            
            for(int i=0; i<11; i++)
            	co_R_Value[i] = 0.0;
            
    	} else {
            jspnR1KA.setValue(coItem.getKa());
            jspnR1KB.setValue(coItem.getKb());
            jspnR1KC.setValue(coItem.getKc());
            jspnR1KD.setValue(coItem.getKd());
            jspnR1KE.setValue(coItem.getKe());
            jspnR1KF.setValue(coItem.getKf());
            jspnRBandC.setValue(coItem.getCPercentage());
            jspnRBandE.setValue(coItem.getEPercentage());
            jspnTargetTaperR.setValue(coItem.getTargetValue());
            jspnUCLTaperR.setValue(coItem.getUcl());
            jspnLCLTaperR.setValue(coItem.getLcl());
            
            co_R_Value[0] = coItem.getKa();
            co_R_Value[1] = coItem.getKb();
            co_R_Value[2] = coItem.getKc();
            co_R_Value[3] = coItem.getKd();
            co_R_Value[4] = coItem.getKe();
            co_R_Value[5] = coItem.getKf();
            co_R_Value[6] = coItem.getCPercentage();
            co_R_Value[7] = coItem.getEPercentage();
            co_R_Value[8] = coItem.getTargetValue();
            co_R_Value[9] = coItem.getUcl();
            co_R_Value[10] = coItem.getLcl(); 
            
            //set the JSpinner to accept Double.
            initJSpinner();
    	}
    }
    
    private void editCoefficientValue()
    {
        // When user trying to Edit Pressure Value, authenticate the user first.
        // If Autehnticated, save the value, else prompt to enter the user again
        String username = null;
        boolean isEdit = false;
        do
        {
            username = Authentication.authenticateUser();
            if(username.equals("Invalid"))
            {
                JOptionPane.showMessageDialog(this, "Your username is invalid.\nPlease enter your username again.", "Authentication Failure", JOptionPane.WARNING_MESSAGE);
                System.out.println("Authentication failure attempted."); //Can be included into activity log later.
                continue;
            }
            else if (username.equals("Exit"))
            {
                System.out.println("Edit coefficient values action terminated."); //Can be included into activity log later.
                break;
            }
            else
            {
                if (username != null)
                {
                    isEdit = true;
                    userID = username;
                    //After Authentication, set all the fields to edittable.
                    toggleTextAndButtons(true);
                }
            }
        }while(isEdit == false);
    }
    private void saveCoefficientValue()
    {
    	
    	//get all the inputs and validate them
        Container c = this.getContentPane();
        Component[] comps = c.getComponents();
        ArrayList<Component> compList = new ArrayList <Component>();
        
        //looping textfields for validation
        for (Component comp : comps)
        {
            if (comp instanceof JSpinner)
            {
                compList.add(comp);
            }
        }
        
        //validate the user input
    	boolean isBlank = Validator.validateBlank_Spinner(compList);
    	
    	if(!isBlank)
    	{
    		DatabaseManager db = new DatabaseManager();
    		
    	    // Save Left Coefficient
    		CoefficientPK coItem_PK = new CoefficientPK();
    		coItem_PK.setArm("L");
    		coItem_PK.setStationName(jcbPolisher.getSelectedItem().toString());
    		
    		Coefficient coItem = new Coefficient();
    		coItem.setId(coItem_PK);
    		coItem.setKa(Double.parseDouble(jspnL1KA.getValue().toString()));
    		coItem.setKb(Double.parseDouble(jspnL1KB.getValue().toString()));
    		coItem.setKc(Double.parseDouble(jspnL1KC.getValue().toString()));
    		coItem.setKd(Double.parseDouble(jspnL1KD.getValue().toString()));
    		coItem.setKe(Double.parseDouble(jspnL1KE.getValue().toString()));
    		coItem.setKf(Double.parseDouble(jspnL1KF.getValue().toString()));
    		coItem.setCPercentage(Double.parseDouble(jspnLBandC.getValue().toString()));
    		coItem.setEPercentage(Double.parseDouble(jspnLBandE.getValue().toString()));
    		coItem.setTargetValue(Double.parseDouble(jspnTargetTaperL.getValue().toString()));
    		coItem.setUcl(Double.parseDouble(jspnUCLTaperL.getValue().toString()));
    		coItem.setLcl(Double.parseDouble(jspnLCLTaperL.getValue().toString()));
    		
    		if(!db.updateCoefficient(coItem))
    		{
        		JOptionPane.showMessageDialog(null, "Failed to update Coefficient Value.", "Update Failed", JOptionPane.WARNING_MESSAGE);
        		return ;
        	}
    		
    		String activityLog_action = "Update Coefficient Value. Station "+coItem_PK.getStationName()+coItem_PK.getArm()+ ": ";
    		activityLog_action += jspnL1KA.getValue().toString() +", ";
    		activityLog_action += jspnL1KB.getValue().toString() +", ";
    		activityLog_action += jspnL1KC.getValue().toString() +", ";
    		activityLog_action += jspnL1KD.getValue().toString() +", ";
    		activityLog_action += jspnL1KE.getValue().toString() +", ";
    		activityLog_action += jspnL1KF.getValue().toString() +", ";
    		activityLog_action += jspnLBandC.getValue().toString() +", ";
    		activityLog_action += jspnLBandE.getValue().toString() +", ";
    		activityLog_action += jspnTargetTaperL.getValue().toString() +", ";
    		activityLog_action += jspnUCLTaperL.getValue().toString() +", ";
    		activityLog_action += jspnLCLTaperL.getValue().toString() +", ";
    		Activity.log(activityLog_action, userID, "Coefficient Value adjustment");
    		
    		// Save Right Coefficient
    		coItem_PK = new CoefficientPK();
    		coItem_PK.setArm("R");
    		coItem_PK.setStationName(jcbPolisher.getSelectedItem().toString());
    		
    		coItem = new Coefficient();
    		coItem.setId(coItem_PK);
    		coItem.setKa(Double.parseDouble(jspnR1KA.getValue().toString()));
    		coItem.setKb(Double.parseDouble(jspnR1KB.getValue().toString()));
    		coItem.setKc(Double.parseDouble(jspnR1KC.getValue().toString()));
    		coItem.setKd(Double.parseDouble(jspnR1KD.getValue().toString()));
    		coItem.setKe(Double.parseDouble(jspnR1KE.getValue().toString()));
    		coItem.setKf(Double.parseDouble(jspnR1KF.getValue().toString()));
    		coItem.setCPercentage(Double.parseDouble(jspnRBandC.getValue().toString()));
    		coItem.setEPercentage(Double.parseDouble(jspnRBandE.getValue().toString()));
    		coItem.setTargetValue(Double.parseDouble(jspnTargetTaperR.getValue().toString()));
    		coItem.setUcl(Double.parseDouble(jspnUCLTaperR.getValue().toString()));
    		coItem.setLcl(Double.parseDouble(jspnLCLTaperR.getValue().toString()));
    		
    		if(!db.updateCoefficient(coItem))
    		{
        		JOptionPane.showMessageDialog(null, "Failed to update Coefficient Value.", "Update Failed", JOptionPane.WARNING_MESSAGE);
        		return ;
        	}
    		
    		activityLog_action = "Update Coefficient Value. Station "+coItem_PK.getStationName()+coItem_PK.getArm()+ ": ";
    		activityLog_action += jspnR1KA.getValue().toString() +", ";
    		activityLog_action += jspnR1KB.getValue().toString() +", ";
    		activityLog_action += jspnR1KC.getValue().toString() +", ";
    		activityLog_action += jspnR1KD.getValue().toString() +", ";
    		activityLog_action += jspnR1KE.getValue().toString() +", ";
    		activityLog_action += jspnR1KF.getValue().toString() +", ";
    		activityLog_action += jspnRBandC.getValue().toString() +", ";
    		activityLog_action += jspnRBandE.getValue().toString() +", ";
    		activityLog_action += jspnTargetTaperR.getValue().toString() +", ";
    		activityLog_action += jspnUCLTaperR.getValue().toString() +", ";
    		activityLog_action += jspnLCLTaperR.getValue().toString() +", ";
    		Activity.log(activityLog_action, userID, "Coefficient Value adjustment");
    		
	    	// Save default values
	    	co_L_Value[0] = Double.parseDouble(jspnL1KA.getValue().toString());
	    	co_L_Value[1] = Double.parseDouble(jspnL1KB.getValue().toString());
	    	co_L_Value[2] = Double.parseDouble(jspnL1KC.getValue().toString());
	    	co_L_Value[3] = Double.parseDouble(jspnL1KD.getValue().toString());
	    	co_L_Value[4] = Double.parseDouble(jspnL1KE.getValue().toString());
	    	co_L_Value[5] = Double.parseDouble(jspnL1KF.getValue().toString());
	    	co_L_Value[6] = Double.parseDouble(jspnLBandC.getValue().toString());
	    	co_L_Value[7] = Double.parseDouble(jspnLBandE.getValue().toString());
	    	co_L_Value[8] = Double.parseDouble(jspnTargetTaperL.getValue().toString());
	    	co_L_Value[9] = Double.parseDouble(jspnUCLTaperL.getValue().toString());
	    	co_L_Value[10] = Double.parseDouble(jspnLCLTaperL.getValue().toString());
	    	
	    	co_R_Value[0] = Double.parseDouble(jspnR1KA.getValue().toString());
	    	co_R_Value[1] = Double.parseDouble(jspnR1KB.getValue().toString());
	    	co_R_Value[2] = Double.parseDouble(jspnR1KC.getValue().toString());
	    	co_R_Value[3] = Double.parseDouble(jspnR1KD.getValue().toString());
	    	co_R_Value[4] = Double.parseDouble(jspnR1KE.getValue().toString());
	    	co_R_Value[5] = Double.parseDouble(jspnR1KF.getValue().toString());
	    	co_R_Value[6] = Double.parseDouble(jspnRBandC.getValue().toString());
	    	co_R_Value[7] = Double.parseDouble(jspnRBandE.getValue().toString());
	    	co_R_Value[8] = Double.parseDouble(jspnTargetTaperR.getValue().toString());
	    	co_R_Value[9] = Double.parseDouble(jspnUCLTaperR.getValue().toString());
	    	co_R_Value[10] = Double.parseDouble(jspnLCLTaperR.getValue().toString());    	
   	
	    	JOptionPane.showMessageDialog(null, "Coefficient Values successfully updated.", "Update Successfully", JOptionPane.PLAIN_MESSAGE);
	    	toggleTextAndButtons(false);
	    	
    	}
    }
    
    private void cancelCoefficientValue()
    {

		jspnL1KA.setValue(co_L_Value[0]);
    	jspnL1KB.setValue(co_L_Value[1]);
    	jspnL1KC.setValue(co_L_Value[2]);
    	jspnL1KD.setValue(co_L_Value[3]);
    	jspnL1KE.setValue(co_L_Value[4]);
    	jspnL1KF.setValue(co_L_Value[5]);
    	jspnLBandC.setValue(co_L_Value[6]);
        jspnLBandE.setValue(co_L_Value[7]);
        jspnTargetTaperL.setValue(co_L_Value[8]);
        jspnUCLTaperL.setValue(co_L_Value[9]);
        jspnLCLTaperL.setValue(co_L_Value[10]);   
        
        jspnR1KA.setValue(co_R_Value[0]);
        jspnR1KB.setValue(co_R_Value[1]);
        jspnR1KC.setValue(co_R_Value[2]);
        jspnR1KD.setValue(co_R_Value[3]);
        jspnR1KE.setValue(co_R_Value[4]);
        jspnR1KF.setValue(co_R_Value[5]);
        jspnRBandC.setValue(co_R_Value[6]);
        jspnRBandE.setValue(co_R_Value[7]);
        jspnTargetTaperR.setValue(co_R_Value[8]);
        jspnUCLTaperR.setValue(co_R_Value[9]);
        jspnLCLTaperR.setValue(co_R_Value[10]);
    }
    
    private void toggleTextAndButtons(boolean isEdittable)
    {
        //If user select 'save', the isEdittable should be false
        //else if user select 'edit', the isEdittable should be true
    	jspnL1KA.setEnabled(isEdittable);
    	jspnL1KB.setEnabled(isEdittable);
    	jspnL1KC.setEnabled(isEdittable);
    	jspnL1KD.setEnabled(isEdittable);
    	jspnL1KE.setEnabled(isEdittable);
    	jspnL1KF.setEnabled(isEdittable);
    	jspnLBandC.setEnabled(isEdittable);
        jspnLBandE.setEnabled(isEdittable);
        jspnLCLTaperL.setEnabled(isEdittable);
        jspnLCLTaperR.setEnabled(isEdittable);
        jspnR1KA.setEnabled(isEdittable);
        jspnR1KB.setEnabled(isEdittable);
        jspnR1KC.setEnabled(isEdittable);
        jspnR1KD.setEnabled(isEdittable);
        jspnR1KE.setEnabled(isEdittable);
        jspnR1KF.setEnabled(isEdittable);
        jspnRBandC.setEnabled(isEdittable);
        jspnRBandE.setEnabled(isEdittable);
        jspnTargetTaperL.setEnabled(isEdittable);
        jspnTargetTaperR.setEnabled(isEdittable);
        jspnUCLTaperL.setEnabled(isEdittable);
        jspnUCLTaperR.setEnabled(isEdittable);
        
        //set the availability of button
        jbtSave.setEnabled(isEdittable);
        jbtCancel.setEnabled(isEdittable);
        jbtEdit.setEnabled(!isEdittable);
        jcbPolisher.setEnabled(!isEdittable);
    }
    
    /**
     * This method is to set the Model of JSpinner to accept Decimal
     * The step size is hard coded to 0.01
     * @param JSpinner js, double def, double min, double max
     */
    private void setJSpinner(JSpinner js, Object defValue, double min, double max)
    {
        double def = Double.parseDouble(defValue.toString());
        js.setModel(new SpinnerNumberModel(def,min,max,0.01));
        js.setEditor(new JSpinner.NumberEditor(js,"##.##"));
    }
    
    /**
     * This method is to set all the JSpinner to accept Decimal
     * The step size is hard coded to 0.01
     * @param 
     */
    private void initJSpinner()
    {
        setJSpinner(jspnL1KA,jspnL1KA.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnL1KB,jspnL1KB.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnL1KC,jspnL1KC.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnL1KD,jspnL1KD.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnL1KE,jspnL1KE.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnL1KF,jspnL1KF.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnLBandC,jspnLBandC.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnLBandE,jspnLBandE.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnLCLTaperL,jspnLCLTaperL.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnLCLTaperR,jspnLCLTaperR.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KA,jspnR1KA.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KB,jspnR1KB.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KC,jspnR1KC.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KD,jspnR1KD.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KE,jspnR1KE.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KF,jspnR1KF.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnR1KF,jspnR1KF.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnRBandC,jspnRBandC.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnRBandE,jspnRBandE.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnTargetTaperL,jspnTargetTaperL.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnTargetTaperR,jspnTargetTaperR.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnUCLTaperL,jspnUCLTaperL.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());
        setJSpinner(jspnUCLTaperR,jspnUCLTaperR.getValue(), PropertiesLoader.getCoefficientLowerLimit(), PropertiesLoader.getCoefficientUpperLimit());

    }
    
    public void addNotify() {
        super.addNotify();
        // Buffer
        createBufferStrategy(2);           
        //BufferStrategy strategy = getBufferStrategy();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CoefficientValueSettingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CoefficientValueSettingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CoefficientValueSettingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CoefficientValueSettingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CoefficientValueSettingFrame().setVisible(true);
            }
        });
    }
    /****************************************************************************
     * INTERNAL OPERATIONS : THE FRAME
     ****************************************************************************/
    
    /**
     * Prompts up a confirmation dialog to confirm the exit action.
     * Upon confirmation, dispose the frame.
     */
    private void onExit()
    {
            this.dispose();
            cancelCoefficientValue();
            toggleTextAndButtons(false);
    }
    
    /**
     * This is a hack for user to click on the 'x' button on window
     */
    protected void processWindowEvent(WindowEvent we)
    {
            if(we.getID() == WindowEvent.WINDOW_CLOSING)
                    onExit();
    }
    
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JButton jbtCancel;
    private javax.swing.JButton jbtEdit;
    private javax.swing.JButton jbtSave;
    private javax.swing.JComboBox jcbPolisher;
    private javax.swing.JLabel jlbL1;
    private javax.swing.JLabel jlbL10;
    private javax.swing.JLabel jlbL11;
    private javax.swing.JLabel jlbL12;
    private javax.swing.JLabel jlbL13;
    private javax.swing.JLabel jlbL2;
    private javax.swing.JLabel jlbL3;
    private javax.swing.JLabel jlbL4;
    private javax.swing.JLabel jlbL5;
    private javax.swing.JLabel jlbL6;
    private javax.swing.JLabel jlbLfactor;
    private javax.swing.JLabel jlbPolisher;
    private javax.swing.JLabel jlbR1;
    private javax.swing.JLabel jlbR2;
    private javax.swing.JLabel jlbR3;
    private javax.swing.JLabel jlbR4;
    private javax.swing.JLabel jlbR5;
    private javax.swing.JLabel jlbR6;
    private javax.swing.JLabel jlbRfactor;
    private javax.swing.JSpinner jspnL1KA;
    private javax.swing.JSpinner jspnL1KB;
    private javax.swing.JSpinner jspnL1KC;
    private javax.swing.JSpinner jspnL1KD;
    private javax.swing.JSpinner jspnL1KE;
    private javax.swing.JSpinner jspnL1KF;
    private javax.swing.JSpinner jspnLBandC;
    private javax.swing.JSpinner jspnLBandE;
    private javax.swing.JSpinner jspnLCLTaperL;
    private javax.swing.JSpinner jspnLCLTaperR;
    private javax.swing.JSpinner jspnR1KA;
    private javax.swing.JSpinner jspnR1KB;
    private javax.swing.JSpinner jspnR1KC;
    private javax.swing.JSpinner jspnR1KD;
    private javax.swing.JSpinner jspnR1KE;
    private javax.swing.JSpinner jspnR1KF;
    private javax.swing.JSpinner jspnRBandC;
    private javax.swing.JSpinner jspnRBandE;
    private javax.swing.JSpinner jspnTargetTaperL;
    private javax.swing.JSpinner jspnTargetTaperR;
    private javax.swing.JSpinner jspnUCLTaperL;
    private javax.swing.JSpinner jspnUCLTaperR;
    // End of variables declaration
    private String userID;
    private Double co_L_Value[] = new Double[11];
    private Double co_R_Value[] = new Double[11];
}

